package tt.dz.service.imp.sys;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class BillProcessFactory implements ApplicationContextAware
{

	private static Log log = LogFactory.getLog(BillProcessFactory.class);

	private static ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
	{
		log.debug("Init application context");
		this.applicationContext = applicationContext;
	}

	public static UploadBillProcess getBillProcessInstance(String cardNo)
	{
		// 线下充值卡
		if (cardNo.startsWith("18806"))
		{
			return applicationContext.getBean(OfflineCardBillProcess.class);
		}
		//身份认证卡
		else if (cardNo.startsWith("18805"))
		{
			return applicationContext.getBean(IdentifyCardBillProcess.class);
		}
		//线上卡app用户
		//else if (cardNo.startsWith("18808") && !cardNo.substring(0, 9).equals("188089999"))  //已发卡，没有按照此规则来做
		else if (cardNo.startsWith("18808") )
		{
			return applicationContext.getBean(OnlineAppCardBillProcess.class);
		}
		// 线上卡企业用户
		else if (cardNo.startsWith("18808"))
		{
			return applicationContext.getBean(OnlineCompanyCardBillProcess.class);
		}
		else
			return null;

	}
}
